package com.sap.apitest2.deprecated.process;

import java.util.Collection;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import com.sap.apitest2.entity.Case;


public class CaseProcess extends EntityProcess {
	
	
	public Collection<Case> getCasesByCatalog(Long id)throws Exception{
		EntityManager em = this.getEntityManager();
		try{			
			Query q = em.createQuery("SELECT p FROM "+Case.class.getName()+" p WHERE P.catalogId=?1");
			q.setParameter(1, id);
			
		    @SuppressWarnings("unchecked")
			List<Case> results = q.getResultList();			
			return results;
		}
		catch(Exception ex){
			throw ex;//this.LogException(ex);
		}
		finally{
			this.releaseEntityManager(em);
		}
	}
/*	public void saveCase(Case entity)throws Exception{
		EntityManager em = this.getEntityManager();
		try{	
			em.getTransaction().begin();
			if(entity.getId()!=null && entity.getId()>0){
				
				Case target = em.find(Case.class, entity.getId());
				//target.setId(entity.getId());
				target.setName(entity.getName());
				target.setCatalogId(entity.getCatalogId());
				em.merge(target);	
				
			}
			else{
				em.persist(entity);		
			}
			em.getTransaction().commit();			
		}
		catch(Exception ex){
			em.getTransaction().rollback();
			throw ex;
		}
		finally{
			this.releaseEntityManager(em);
		}
	}*/
}
